# cat << EOF > /dev/null

# -- general
# set-option default-path "$PWD"

# 配置加载按键绑定
bind r source-file ~/.config/tmux/tmux.conf 
bind -n C-z source-file ~/.config/tmux/tmux-lock.conf 

#lock按键绑定############################################################
bind -n M-o split-window -v -c "#{pane_current_path}" #向下切分窗口
bind -n M-p split-window -h -c "#{pane_current_path}" #向右切分窗口

# pane 的方向选择
bind -n M-h select-pane -L
bind -n M-j select-pane -D
bind -n M-k select-pane -U
bind -n M-l select-pane -R

# 切换布局
bind -n C-x next-layout

bind -n M-i kill-pane #关闭pane

# pane 大小调整
bind -n C-t resize-pane -L 3
bind -n C-j resize-pane -D 3
bind -n C-k resize-pane -U 3
bind -n C-r resize-pane -R 3
bind -n C-f resize-pane -Z  #最大化

#创建新窗口
bind -n M-n new-window -c "#{pane_current_path}"
#关闭新窗口
bind -n M-m kill-window

bind -n C-h previous-window
bind -n C-l next-window

bind -n "M-;" swap-pane -D #顺时针交换窗口
bind -n "M-'" swap-pane -U #逆时针交换窗口

bind -n "M-=" "run -b 'bash ~/.config/tmux/custom.tmux move_win_to_right'"
bind -n "M--" "run -b 'bash ~/.config/tmux/custom.tmux move_win_to_left'"

bind -n C-p paste-buffer
###########################################################################

unbind C-b                 
set -g prefix 'M-u'   #主按键

bind -n C-q kill-session   #杀死会话

bind o split-window -v -c "#{pane_current_path}" #向下切分窗口
bind p split-window -h -c "#{pane_current_path}" #向右切分窗口

bind i kill-pane #关闭pane
bind a resize-pane -Z #触发pane最大化和最大化还原

# pane 的方向选择
bind ! join-pane -t :1
bind @ join-pane -t :2
bind '#' join-pane -t :3
bind '$' join-pane -t :4
bind % join-pane -t :5
bind ^ join-pane -t :6
bind & join-pane -t :7
bind * join-pane -t :8
bind ( join-pane -t :9
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind O choose-tree 'move-pane -v -s "%%"' # 全局选择一个pane放到当前的下边
bind P choose-tree 'move-pane -h -s "%%"' # 全局选择一个pane放到当前右边
bind b break-pane # 将pane放到新窗口


#创建新窗口
bind n new-window -c "#{pane_current_path}"
#关闭新窗口
bind m kill-window
bind 1 select-window -t 1
bind 2 select-window -t 2
bind 3 select-window -t 3
bind 4 select-window -t 4
bind 5 select-window -t 5
bind 6 select-window -t 6
bind 7 select-window -t 7
bind 8 select-window -t 8
bind 9 select-window -t 9
bind y previous-window
bind u next-window

#pane 同步输入触发
bind s if-shell '[[ $(tmux showw synchronize-panes | cut -d\  -f2) == "on" ]]' \
'setw synchronize-panes off; set -g pane-border-style fg=#94e661' \
'setw synchronize-panes on; set -g pane-border-style fg=red'

#窗口模糊查找
bind f "run -b 'bash ~/.config/tmux/fzf_panes.tmux new_window'"

#窗口全局预览选择 f
bind w choose-tree -Z

#pane文本编辑
bind e "run  'bash ~/.config/tmux/custom.tmux edit_pane'"

#alt u 可以用编辑器编辑当前终端的文本

#leader+[ 进入复制模式 方向移动光标 space切入选中模式 方向移动选中 enter确认选中 leader+]

#leader+d挂起

# 好像是监听pane聚焦后就记住pane的什么信息的
set-hook -g pane-focus-in "run -b 'bash ~/.config/tmux/fzf_panes.tmux update_mru_pane_ids'"


setw -g xterm-keys on
set -s escape-time 0
set -sg repeat-time 300
set -s focus-events on
set -g mouse off
set -sg exit-empty on

set -q -g status-utf8 on
setw -q -g utf8 on

set -g visual-activity off
setw -g monitor-activity off
setw -g monitor-bell off

set -g history-limit 10000


set -ga update-environment '\
DISPLAY DBUS_SESSION_BUS_ADDRESS \
QT_IM_MODULE QT_QPA_PLATFORMTHEME \
SESSION_MANAGER \
XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME\
XDG_MENU_PREFIX XDG_RUNTIME_DIR XDG_SESSION_CLASS \
XDG_SESSION_DESKTOP XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \
XMODIFIERS \
FZF_DEFAULT_OPTS \
'
set-hook -g client-attached 'run -b "cut -c3- ~/.tmux.conf | sh -s update_env_event"'

# -- prefix


# -- display
set -g base-index 1
setw -g pane-base-index 1

setw -g automatic-rename on
set -g renumber-windows on

set -g set-titles on

set -g display-panes-time 2000
set -g display-time 2000

set -g status-interval 1

# set -g status-keys emacs
# set -g mode-keys vi

# bind -n M-v copy-mode

bind -T copy-mode-vi v send-keys -X begin-selection
# bind -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind -T copy-mode-vi h send-keys -X cursor-left
bind -T copy-mode-vi l send-keys -X cursor-right
bind -T copy-mode-vi k send-keys -X cursor-up
bind -T copy-mode-vi j send-keys -X cursor-down
bind -T copy-mode-vi L send-keys -X next-word-end
bind -T copy-mode-vi H send-keys -X previous-word
bind -T copy-mode-vi K send-keys -N 5 -X cursor-up
bind -T copy-mode-vi J send-keys -N 5 -X cursor-down
bind -T copy-mode-vi b send-keys -X start-of-line
bind -T copy-mode-vi e send-keys -X end-of-line
# bind -T copy-mode-vi Y send-keys -X copy-end-of-line
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# bind -T copy-mode-vi = send-keys -X search-again
# bind -T copy-mode-vi = send-keys -X search-reverse

# -- toggle_status
# bind s if-shell '[[ $(tmux show -g status | cut -d\  -f2) == "on" ]]' \
# 'set -g status off' \
# 'set -g status on'

# -- theme
#set -g status off

# panes
setw -g pane-border-status top
# setw -g pane-border-format '#[bold]#{?#{&&:#{pane_active},#{client_prefix}},#[fg=pink],}< #{?#{&&:#{pane_active},#{client_prefix}}, ,}slack #P ⇒ #{pane_current_command} >'
setw -g pane-border-format '|#[bold,fg=#000000]#{?#{pane_active},#[bg=#75af00],#[fg=#DF9500]}#P ⇒ #{pane_current_command}#[bg=default]#{?#{pane_active},#[fg=#75af00],#[fg=#DF9500]}|'
# setw -g pane-border-format '#[bold]#{?#{&&:#{pane_active},#{client_prefix}},#[underscore],}\
# #{?pane_active,❐ #S:#I/#{session_windows} ,}#{?window_zoomed_flag,⬢,❄} #P ⇒ #{pane_tty} #{pane_current_command}'
set -g pane-active-border-style fg=#94e661
set -g pane-border-style fg=#DF9500

# windows
set -g status-justify 'centre'
set -g status-left-length 90
set -g status-right-length 140
setw -g window-status-separator ''
set-option -g status-position bottom

# default statusbar colors
set -g status-bg "#000000"
#set -g status-left ' #[fg=#94e661,bold]❐ #S'
#set -g status-left '#[fg=brightyellow] #{?client_prefix,⌨ ,  }  #[fg=#94e661,bold] %Y-%m-%d %H:%M '
#set -g status-right '#(rainbarf --battery --remaining --bolt --tmux --rgb)'
#set -g status-left "#[fg=#94e661,bold] %Y-%m-%d %H:%M | #[fg=#DF9500]#(curl icanhazip.com) #(ifconfig en0 | grep 'inet ' | awk '{print \"en0 \" $2}') #(ifconfig en1 | grep 'inet ' | awk '{print \"en1 \" $2}') #(ifconfig en3 | grep 'inet ' | awk '{print \"en3 \" $2}') #(ifconfig tun0 | grep 'inet ' | awk '{print \"vpn \" $2}') "

# set -g status-left "#[fg=#94e661,bold] #S"


setw -g window-status-format '#[bold,bg=#262626,fg=#AF8700] #I ⇒ #W '
setw -g window-status-current-format '#[fg=#000000,bold]#{?#{&&:#{pane_active},#{client_prefix}},#[bg=#75af00],#[bg=#c0830b,bold]} #{?#{&&:#{pane_active},#{client_prefix}}, ,}#I ⇒ #W #{?#{window_zoomed_flag},󰊓 ,}'
setw -g window-status-activity-style bg=black
setw -g window-status-bell-style bg=black
#set-window-option -g window-status-current-format "#[fg=colour235, bg=colour27]⮀#[fg=colour255, bg=colour27] #I ⮁ #W #[fg=colour27, bg=colour235]⮀"

set -g status-right "#[bold,bg=#262626,fg=#AF8700] #S:#P/#{window_panes}  "
set -g status-left "#[bold,bg=#262626,fg=#AF8700]   LOOSE   "
# set-option -g status-left "#(~/.config/tmux/tmux-powerline/powerline.sh left)"
# set-option -g status-right "#(~/.config/tmux/tmux-powerline/powerline.sh right)"


run-shell ~/.config/tmux/plugins/tmux-resurrect/resurrect.tmux
set -g @resurrect-save 'C-s'
set -g @resurrect-restore 'C-r'
set -g @resurrect-dir '~/file/tmux-session-save'
set -g @resurrect-processes 'tycloud lazygit v gdb'
